import 'package:flutter/material.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

import '../../tool/assets.dart';
import 'slider_item.dart';
import 'slope_item.dart';
import 'type_item.dart';

class PassView extends GetxPassView {
  const PassView({super.key, required super.tag});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      Passmodel model = controller.rxModel.value;
      return Container(
        padding: const EdgeInsets.only(left: 10, right: 10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          spacing: 10,
          children: [
            ///标题
            Text(model.name, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),

            ///底部相关设置部分
            Flexible(
                flex: 10,
                child: Row(
                  spacing: 10,
                  children: [
                    Flexible(
                      flex: 1,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          ///图形
                          Flexible(
                              flex: 8,
                              child: Image.asset(model.ishigh ? assets.pass_high : assets.pass_low,
                                  fit: BoxFit.scaleDown)),
                          const SizedBox(height: 15),

                          ///switch开关
                          Flexible(
                            child: Transform.scale(
                              scale: 0.8,
                              child: Switch(
                                  value: model.select,
                                  onChanged: (ison) => globalController.updatePassSwitch(model, ison)),
                            ),
                          ),
                        ],
                      ),
                    ),
                    Flexible(
                      flex: 2,
                      child: Column(
                        spacing: 8,
                        children: [
                          ///SLOPE
                          Flexible(
                            flex: 2,
                            child: SlopeItem(
                                flex1: 1,
                                flex2: 3,
                                model: model,
                                onClick: (p0) => globalController.updateSlope(model, p0)),
                          ),

                          ///TYPE
                          Flexible(
                              flex: 2,
                              child: TypeItem(
                                  flex1: 1,
                                  flex2: 3,
                                  name: 'TYPE',
                                  model: model,
                                  onClick: (isadd) => globalController.changeFilterType(model, !isadd))),

                          ///FREQ按钮
                          Flexible(
                            flex: 2,
                            child: TypeItem(
                                flex1: 1,
                                flex2: 3,
                                name: 'FREQ',
                                model: model,
                                onClick: (isadd) => globalController
                                    .updatePassFreq(model, isadd ? model.freq + 1 : model.freq - 1, isSend: true)),
                          ),

                          ///FREQ滑动
                          Flexible(
                            flex: 2,
                            child: PassSlider(
                                flex1: 1,
                                flex2: 3,
                                model: model,
                                onChange: (p0) => globalController.updatePassFreq(model, p0.round()),
                                onChangedForSend: (p0) =>
                                    globalController.updatePassFreq(model, p0.round(), isSend: true)),
                          ),
                        ],
                      ),
                    ),
                  ],
                )),
          ],
        ),
      );
    });
  }
}
